package com.qeegoo.b2bautozityp.moudle.good.view.carmodel;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;

import com.qeegoo.b2bautozityp.R;
import com.qeegoo.b2bautozityp.databinding.FragGoodsCarmodelMainBinding;
import com.qeegoo.b2bautozityp.moudle.base.BaseFragment;
import com.qeegoo.b2bautozityp.moudle.good.viewmodel.carmodel.CarModelMainViewModel;

/**
 * 王少岩 在 2017/9/22 创建了它
 */

public class CarModelMainFragment extends BaseFragment<FragGoodsCarmodelMainBinding> {
    private CarModelMainViewModel mViewModel;
    private CarModelSelectFragment mSelectFragment;
    private CarModelAddFragment mAddFragment;

    @Override
    protected int attachLayoutRes() {
        return R.layout.frag_goods_carmodel_main;
    }

    @Override
    protected void initInjector() {
    }

    @Override
    protected void initViews() {
        mViewModel = new CarModelMainViewModel();
        mBinding.setViewModel(mViewModel);
        mBinding.rbSelect.setChecked(true);
        mSelectFragment = new CarModelSelectFragment();
        mAddFragment = new CarModelAddFragment();
        showFragments(mSelectFragment);
        setListener();
    }

    private void setListener() {
        mBinding.rgCarmodel.setOnCheckedChangeListener((group, checkedId) -> {
            switch (checkedId) {
                case R.id.rb_select:
                    showFragments(mSelectFragment);
                    break;
                case R.id.rb_add:
                    showFragments(mAddFragment);
                    break;
            }
        });
    }


    private void showFragments(Fragment fragment) {
        FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
        transaction.replace(R.id.layout_container, fragment);
        transaction.commitAllowingStateLoss();
    }

}
